package com.af.system.util;

import com.af.system.enums.AfNamingRuleEnum;

import java.lang.reflect.Array;
import java.nio.charset.Charset;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author : zhenyun.su
 * @comment : object 工具类
 * @since : 2022/09/13
 */

public abstract class AfCollectionUtils {
    
    /*
     * @comment : 按命名规则，转换Map的key的名称
     */
    public static Map<String,Object> convertMapForNaming(Map<String,Object> source, AfNamingRuleEnum ruleEnum){
        Map taget = new HashMap();
        for (String s : source.keySet()) {
            taget.put(ruleEnum.naming(s), source.get(s));
        }
        return taget;
    }

    /*
     * @comment : 按命名规则，List的Map的key转换
     */
    public static List<Map<String,Object>> convertListForNaming(List<Map<String,Object>> sources, AfNamingRuleEnum ruleEnum){
        if (AfObjectUtils.isEmpty(sources)){
            return null;
        }
        List<Map<String,Object>> targets = sources.stream().map(source -> convertMapForNaming(source, ruleEnum)).collect(Collectors.toList());
        return targets;
    }


    /*
     * @comment : 返回Integer类型的List， 用于data-jpa的 in 查询
     */
    public static List<Integer> listValue(Integer o, Integer ...defaultVale){
        if (o ==  null){
            return Arrays.asList(defaultVale);
        }else{
            return Arrays.asList(o);
        }
    }
    public static List<Long> listValue(Long o, Long ...defaultVale){
        if (o ==  null){
            return Arrays.asList(defaultVale);
        }else{
            return Arrays.asList(o);
        }
    }
}
